﻿using movie.tool.library.ui;
using movie.tool.module.film.model;
using movie.tool.module.film.service;
using System.Windows;

namespace movie.tool.module.film.ui
{
    /// <summary>
    /// MovieDetailPage.xaml 的交互逻辑
    /// </summary>
    public partial class MovieDetailPage : CommonPage
    {
        private MovieProject cfg;
        public MovieProject Config
        {
            get => cfg;
            set
            {
                cfg = value;
                SendPropertyChanged(nameof(Config));
            }
        }
        private BusyInfo busyInfo;
        public BusyInfo BusyInfo
        {
            get => busyInfo;
            set
            {
                busyInfo = value;
                SendPropertyChanged(nameof(BusyInfo));
            }
        }
        /// <summary>
        /// 当前编辑的剧本id
        /// </summary>
        public static long EditMovieId { get; set; }
        public MovieDetailPage()
        {
            InitializeComponent();
            BusyInfo = new BusyInfo();
        }

        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                BusyInfo.Busy = true;
                MovieSynchronizer synchronizer = new MovieSynchronizer(BusyInfo, EditMovieId);
                this.Config = await synchronizer.Synchronise();
            }
            finally
            {
                BusyInfo.Reset();
            }
        }

        private void ReturnClick(object sender, RoutedEventArgs e)
        {
            MainWindow.ShowPage("/module/film/ui/MovieListPage.xaml");
        }
    }
}
